/**
 * Created by gongxun on 16/12/29.
 */

var KwxFeedbackLayer = KwxBaseLayer.extend({
    Panel_center : null,
    mReplayId : null,
    mInputBox : null,
    ctor : function (ReplayId) {
        this._super();
        this.mReplayId = ReplayId;
        this.loadCocostudio("res/ccs/KwxFeedbackLayer.json");
        mo.gameHelper.fixIosText(this.ccsNode);
        this.Panel_center = mo.seekWidgetByName(this.ccsNode, "Panel_center");
        this.TextField_content = mo.seekWidgetByName(this.ccsNode, "TextField_content");

        mo.seekWidgetByName(this.ccsNode, "Button_ok").addTouchEventListener(this.onTouchOk, this);

        mo.seekWidgetByName(this.ccsNode, "Button_close").addTouchEventListener(this.onTouchClose, this);

        mo.seekWidgetByName(this.ccsNode, "Panel_touch").addTouchEventListener(this.onTouchClose, this);


        var inputP = mo.seekWidgetByName(this.ccsNode, "Image_inputBg").getPosition();
        var inputS = mo.seekWidgetByName(this.ccsNode, "Image_inputBg").getContentSize();

        inputP = cc.p(inputP.x + 5 + mo.curSize.x / 2, inputP.y + mo.curSize.y / 2);
        inputS = cc.size(inputS.width - 10, inputS.height - 20);

        this.mInputBox = new cc.EditBox(inputS, new cc.Scale9Sprite("res/ccs/common/Transparent.png"));
        this.mInputBox.setString("");
        this.mInputBox.setPosition(inputP);
        this.mInputBox.setReturnType(cc.KEYBOARD_RETURNTYPE_SEND);
        this.mInputBox.setInputMode(cc.EDITBOX_INPUT_MODE_SINGLELINE);
        this.mInputBox.setFontColor(cc.color(255, 255, 255));
        this.mInputBox.setFontSize(30);
        this.mInputBox.setPlaceHolder("请输入bug描述");
        this.mInputBox.setPlaceholderFontColor(cc.color(255, 255, 255));
        this.mInputBox.setMaxLength(50);
        this.addChild(this.mInputBox);
    },

    onEnter : function(){
        this._super();
        mo.soundHelper.playDialogOpen();
        this.showMsgBox();
    },

    showMsgBox : function(){
        this.showAction(this.Panel_center);
    },

    closeMsgBox : function(){
        if (this.closeAction(this.Panel_center)){

        }
    },

    onTouchOk : function(sender, type){
        if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
            var text = this.mInputBox.getString();
            if (text == ""){
                mo.showRoomMsgShow("请输入问题描述");
            }else{
                if (this.mReplayId != null){
                    mo.gameMsgManager.sendDebugInfo(mo.gameUserInfo.uid, this.mReplayId, text);
                }
                mo.showRoomMsgShow("成功提交反馈");
                this.closeMsgBox();
            }
        }
    },

    onTouchClose : function(sender, type){
        if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
            this.closeMsgBox();
        }
    },

    setContent : function(content){
        mo.seekWidgetByName(this.ccsNode, "Text_content").setString(content);
    }
});
